//
//  PickViewController.m
//  UIpickview
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "PickViewController.h"

@interface PickViewController ()
@property(nonatomic,strong) NSArray *list;
@end

@implementation PickViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.pickview.dataSource = self;
    self.pickview.delegate = self;
    self.list=@[@"佐菲",@"奥特曼",@"赛文",@"杰克",@"艾斯",@"泰罗"];
}

- (IBAction)pressed:(id)sender
{
    int sel=[self.pickview selectedRowInComponent:0];
    NSString *name=self.list[sel];
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"选择了谁" message:name delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
    [alert show];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
{
    return  self.list.count;
}
-(nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.list[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.label.text = self.list[row];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
